import datetime,pymysql
def run_log(log,type='notice'):
    log_file=open('run.log','a')
    msg="\n[%s] [%s] %s"%(str(datetime.datetime.now()),type,log)
    log_file.write(msg)
    log_file.close()
def err_log(log,type='erroe'):
    log_file=open('err.log','a')
    msg="\n[%s] [%s] %s"%(str(datetime.datetime.now()),type,log)
    log_file.write(msg)
    log_file.close()
def talk_log(log):
    log_file=open('talk.log','a')
    msg="\n[%s] %s"%(str(datetime.datetime.now()),log)
    log_file.write(msg)
    log_file.close()
def mysql(sql):
    conn = pymysql.connect(user='RNone', passwd='wr84906440',host='localhost', db='rnone',charset='utf8')
    cur = conn.cursor()
    sql=sql.encode('utf-8')
    try:
        sta=cur.execute(sql)
        conn.commit()
        return cur,sta
    finally:
        cur.close()
        conn.close()



#创建users表
#mysql("create table users (id int auto_increment primary key not null unique,uName varchar(20),uNum varchar(20),uPasswd varchar(20)) character set = utf8;")

#创建records表
#mysql("create table records (id int auto_increment primary key not null unique,uName varchar(20) not null,uMsg varchar(500),uid int,foreign key(uid) references users(id) on delete cascade on update cascade) character set = utf8;")

##调用函数进行操作即可

# cur,sta=mysql('select * from users')
# for i in cur:
#     print(i)
#
# user,sta=mysql("select * from users where username='%s'"%("wr440"))
# for i in user:
#     print(i)